package com.leetcode.partition15;

/**
 * @author `RKC`
 * @date 2021/12/1 9:14
 */
public class LC1446连续字符 {

    public static int maxPower(String s) {
        if (s.length() == 1) return 1;
        return doublePointer(s);
    }

    public static void main(String[] args) {
        System.out.println(maxPower("leetcode"));
        System.out.println(maxPower("abbcccddddeeeeedcba"));
    }

    private static int doublePointer(String s) {
        int ans = 0;
        for (int i = 0, j = 1; j < s.length(); j++) {
            while (j < s.length() && s.charAt(i) == s.charAt(j)) j++;
            ans = Math.max(ans, j - i);
            i = j;
        }
        return ans;
    }

    private static int greedy(String s) {
        int ans = 0, k = 1;
        for (int i = 1; i < s.length(); i++) {
            if (s.charAt(i) == s.charAt(i - 1)) k++;
            else k = 1;
            ans = Math.max(ans, k);
        }
        return ans;
    }
}
